package com.kwshare.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kwshare.common.core.domain.system.UserRole;
import com.kwshare.system.mapper.UserRoleMapper;
import com.kwshare.system.service.IUserRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户角色接口
 *
 * @author yangjing
 */
@Service
public class UserRoleServiceImpl implements IUserRoleService {

    @Resource
    private UserRoleMapper userRoleMapper;

    @Override
    public List<Long> selectRolesByUserId(Long userId) {
        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        List<UserRole> userRoles = userRoleMapper.selectList(queryWrapper);
        List<Long> roleIds = new ArrayList<>();
        for(UserRole userRole : userRoles){
            roleIds.add(userRole.getRoleId());
        }
        return roleIds;
    }
}
